/*
 * server_util.h
 *
 *  Created on: Jan 24, 2011
 *      Author: marco
 */

#ifndef SERVER_UTIL_H_
#define SERVER_UTIL_H_

#include "msg.h"

#define MAX_QUEUE 4


typedef struct user{
	char *name;
	int sfd;
	pthread_t tid;
}user;


/*Strutture dati per la coda di messaggi per il writer*/
typedef struct queue_node{
	char *text;
	struct queue_node *next;
}queue_node;

typedef struct{
	int dim;
	queue_node *head;
	queue_node *tail;
	pthread_mutex_t *mtx;
	pthread_cond_t *e;
	pthread_cond_t *f;
}msg_queue;

/*Semplice linked list per tenere traccia degli utenti online*/
typedef struct user_pointer_t{
	user *user;
	struct user_pointer_t *next;
}user_pointer_t;

typedef struct {
	user_pointer_t *head;
	user *next;
}user_pointers_l;



/*Funzioni per la tabella hash utenti*/
int compare_user(void *, void *);
void * copy_user(void *);
void * copy_string(void *);
void * copy_int(void *);
void free_user(user *);

/*Funzioni per la lista utenti online*/
int insert_user_l(user_pointers_l *, user*);
int remove_user_l(user_pointers_l *, char*);
user* search_user_l(user_pointers_l *, char*);



#endif /* SERVER_UTIL_H_ */
